<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of model_order
 *
 * @author b4by
 */
class model_order extends MY_Model {

	var $table = 'order';

	public function create($data) {

		$this->load->model('model_product');

		$product = $this->model_product->get_info($data['product_id']);

		$this->model_product->update($product->id, array('total_orders' => $product->total_orders + 1));

		return parent::create($data);
	}

	public function update($id, $data) {
		$order = $this->get_info($id);
		if ($order->paid == 0 && $order->cancel == 0)
			if ($data['cancel'] == 1 || $data['paid'] == 1) {
				$this->load->model('model_product');
				$product = $this->model_product->get_info($order->product_id);
				$this->model_product->update($order->product_id, array('total_orders' => $product->total_orders - 1));
			}
		parent::update($id, $data);
	}

	
}

?>
